﻿<template>
     <el-dialog :close-on-click-modal="false"  :close-on-press-escape="false"  title="编辑" :append-to-body="true" :visible="modalEdit" @close="modalEdit=false"  @opened="opened" @closed="closed" >
        <el-form ref="customerAddress" label-position="left" label-width="120px" :model="customerAddress" :rules="rules">
            <input type="hidden" :model="customerAddress.id" />
            <el-form-item label="联系人" prop="linkMan">
                <el-input size="small" v-model="customerAddress.linkMan" placeholder="联系人" style="width: 240px" />
            </el-form-item>
            <el-form-item label="联系电话" prop="phone">
                <el-input size="small" v-model="customerAddress.phone" placeholder="联系电话" style="width: 240px" />
            </el-form-item>
            <el-form-item label="地址" prop="address">
                <el-input size="small" v-model="customerAddress.address" placeholder="地址" style="width: 240px" />
            </el-form-item>
        </el-form>
        <div slot="footer">
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" :loading="modalLoading" @click="ok">确定</el-button>
        </div>
    </el-dialog>
    </div>
</template>
<script>
export default {
    name: 'CustomerAddress',
    data() {
        return {

            modalEdit: false,
            modalLoading: false,
            customerAddressId: "",
            customerAddress: {
                customerId:null
            },
          
            rules: {

            }
        };
    },
    mounted: function() {


    },
    methods: {

        opened() {

            this.getDetail();

        },
        closed: function() {
            this.customerAddress = {

            }
        },
        showDialog(id,customerId) {
            this.customerAddressId = id;
            this.customerAddress.customerId=customerId;
            this.modalEdit = true;
        },
        getDetail: function() {
            if (this.customerAddressId == null || this.customerAddressId == undefined || this.customerAddressId == "") return;
            var me = this;
            me.showLoading();
            me.$http.post("/sys/customeraddress/show_" + me.customerAddressId + ".action").then(response => {
                var body = response;
                if (body.status == 0) {
                    me.customerAddress = body.obj;
                }
                me.hideLoading();
            }, response => {
                me.hideLoading();
            });
        },
        ok: function() {
            var ok = false;
            this.$refs['customerAddress'].validate((valid) => {
                ok = valid;
                if (valid) {

                } else {
                    this.errorMessage('请认真填写数据');
                }
            })
            if (!ok) return;
            var me = this;
            me.modalLoading = true;
            me.$http.post("/sys/customeraddress/doSave.action", me.customerAddress).then(response => {
                var body = response;
                if (body.status == 0) {
                    me.successMessage("保存成功！");
                    me.modalEdit = false;
                    me.$emit("ok");

                } else {
                    me.errorMessage(body.info);
                }
                me.modalLoading = false;
            }, response => {
                me.modalLoading = false;
            });
        },
        cancel: function() {
            this.customerAddress = {};
            this.modalEdit = false;
            this.$emit("cancel");
        }
    }
}
</script>
<style scoped>
</style>